package com.epfly.promo.base;

import com.epfly.base.util.DateUtil;
import com.epfly.base.vo.RowsResp;
import com.epfly.iface.promo.activity.ActivityService;
import com.epfly.iface.promo.activity.enums.*;
import com.epfly.iface.promo.activity.vo.*;
import com.epfly.promo.base.iface.UserService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Arrays;

@Validated
@RestController
public class UserController {

    @Resource
    private UserService userService;

    @Resource
    private ActivityService activityService;

    @GetMapping(value = "/list")
    public ResponseEntity<String> listG() {
        ActivityDetailResp activityDetailResp = activityService.performActivityDetail(8L);
        System.out.println(activityDetailResp);
        return ResponseEntity.ok( "" + LocalDateTime.now());
    }

    @GetMapping(value = "/list2")
    public ResponseEntity<String> listG2() {
        StoreCountRequest request = new StoreCountRequest();
        request.setMerchantId("2021040701");
        request.setActivityStartTime(20220101_112309L);
        request.setActivityEndTime(20230501_112309L);

        RowsResp<StoreCountVo> activityDetailResp = activityService.storeCount(request);
        System.out.println(activityDetailResp);
        return ResponseEntity.ok( "" + LocalDateTime.now());
    }

    @GetMapping(value = "/list3")
    public ResponseEntity<String> listG3() {
        ActivityAddAndUpdateRequest req = new ActivityAddAndUpdateRequest();
        req.setMerchantId("2021040701");
        req.setActivityName("五一111促销");
        req.setActivityType(ActivityTypeEnum.ORDER.getKey());
        req.setDiscountType(DiscountTypeEnum.ORDER_FULL.getKey());

        ActivityRelationVo relationVo = new ActivityRelationVo();
        relationVo.setRelationId("foodId1");

        req.setRelationList(Arrays.asList(relationVo, ActivityRelationVo.builder().relationId("foodId2").build()));
        req.setActivityStartTime(DateUtil.getCurrentTime());

        req.setActivityEndTime(DateUtil.getCurrentTimeWithPlusMinutes(300));
        req.setActivityObjectTypeList(Arrays.asList(ActivityObjectTypeEnum.UN_LIMIT.getKey()));
//        req.setActivityObjectTypeCascade(ActivityObjectTypeCascadeEnum.ASSIGN_DEPT.getKey());
//        req.setObjectIdList(Arrays.asList("deptId11", "deptId22"));

        req.setStoreStyle(StoreStyleEnum.UN_LIMIT.getKey());
//        req.setStoreIdList(Arrays.asList("storeId11", "storeId22"));

        req.setEffectiveDays(Arrays.asList((byte) EffectiveDaysEnum.UN_LIMIT.getKey()));
        req.setIsSuiteHoliday(IsSuiteHolidayEnum.NO.getKey());
        req.setEffectiveOrderMethods(Arrays.asList(EffectiveOrderMethodsEnum.NO_LIMIT.getKey()));
        req.setEffectiveTakeMethods(Arrays.asList(EffectiveTakeMethodsEnum.NO_LIMIT.getKey()));
        req.setRemark("marK");
        req.setRuleList(Arrays.asList(ActivityRuleVo.builder().dinnerType(ActivityRuleDinnerTypeEnum.BREAKFAST.getKey())
                .ruleContent(" {\n" +
                        "        \"name\":\"满减优惠\",\n" +
                        "        \"values\":[\n" +
                        "            {\n" +
                        "                \"upperBound\":\"1\",\n" +
                        "                \"discountAmount\":\"0.8\"\n" +
                        "            },\n" +
                        "            {\n" +
                        "                \"upperBound\":\"100\",\n" +
                        "                \"discountAmount\":\"20\"\n" +
                        "            },\n" +
                        "            {\n" +
                        "                \"upperBound\":\"200\",\n" +
                        "                \"discountAmount\":\"50\"\n" +
                        "            }\n" +
                        "        ]\n" +
                        "    }").build()));
        req.setDinnerBoundList(Arrays.asList(
                ActivityDinnerBoundVo.builder().dinnerType(ActivityRuleDinnerTypeEnum.UN_LIMIT.getKey()).amountBound(new BigDecimal(123)).countBound(23).isActive(IsActiveEnum.YES.getKey()).build())
        );

        ActivityDayBoundVo dayBound =  ActivityDayBoundVo.builder()
                .amountBound(new BigDecimal("8888"))
                .countBound(99)
                .isActive(IsActiveEnum.YES.getKey())
                .build();
        req.setDayBound(dayBound);
        req.setCreateBy("X");;
        ActivityAddAndUpdateResp activityAddAndUpdateResp = activityService.performActivityAdd(req);


        System.out.println(activityAddAndUpdateResp);
        return ResponseEntity.ok( "" + LocalDateTime.now());
    }

//    @GetMapping(value = "/sayHello")
    @RequestMapping(value = "/sayHello", method = RequestMethod.GET)
    public ResponseEntity<String> sayHello(@NotNull(message = "姓名不能不传") @NotEmpty(message = "姓名不能为空") String name) {
        return new ResponseEntity<>("hello world !" + userService.sayHello(name) + ">?1?" + name, HttpStatus.OK);
    }

    @Resource
    private UserServiceFeign userServiceFeign;

    @GetMapping(value = "/getEnhance")
    public String getEnhance(@RequestParam() String name) {

        return "getEnhance " + userServiceFeign.sayHello(name);
    }
}
